package com.xyht.sca_s.student_manage_system.modules.student_difficulty.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.student_difficulty.entity.req.SmsStudentDifficultyTaskReq;
import com.xyht.sca_s.student_manage_system.modules.student_difficulty.service.SmsStudentDifficultyTaskService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 家庭经济困难认定任务 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-03-01
 */
@RestController
@RequestMapping("/difficulty/task")
@SecretBody
public class SmsStudentDifficultyTaskController {
    @Autowired
    private SmsStudentDifficultyTaskService smsStudentDifficultyTaskService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "教师家庭经济困难学生认定任务添加")
    @PostMapping("/add")
    public ResponseResult addStudentInfo(@RequestBody SmsStudentDifficultyTaskReq smsStudentDifficultyTaskReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyTaskService.addDifficultyTask(smsStudentDifficultyTaskReq, user_id);
    }

    @ApiModelProperty(value = "教师家庭经济困难学生认定任务关闭")
    @PostMapping("/close")
    public ResponseResult closeDifficultyTask(@RequestBody SmsStudentDifficultyTaskReq smsStudentDifficultyTaskReq) {
        return smsStudentDifficultyTaskService.closeDifficultyTask(smsStudentDifficultyTaskReq);
    }

    @ApiModelProperty(value = "教师家庭经济困难学生认定任务删除")
    @PostMapping("/delete")
    public ResponseResult deleteDifficultyTask(@RequestBody SmsStudentDifficultyTaskReq smsStudentDifficultyTaskReq) {
        return smsStudentDifficultyTaskService.deleteDifficultyTask(smsStudentDifficultyTaskReq);
    }

    @ApiModelProperty(value = "教师家庭经济困难学生认定任务更新(任务名修改)")
    @PostMapping("/update")
    public ResponseResult updateDifficultyTask(@RequestBody SmsStudentDifficultyTaskReq smsStudentDifficultyTaskReq) {
        return smsStudentDifficultyTaskService.updateDifficultyTask(smsStudentDifficultyTaskReq);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定任务列表")
    @GetMapping("/list")
    public ResponseResult getDifficultyTaskList(HttpServletRequest request,
                                               @RequestParam(value = "is_close", required = false) Integer is_close,
                                               @RequestParam(value = "search_str", required = false) String search_str,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyTaskService.getDifficultyTaskList(pageNum, pageSize, is_close, user_id,search_str);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定任务详情")
    @GetMapping("/detail")
    public ResponseResult getDifficultyTaskDetail(HttpServletRequest request,
                                                 @RequestParam(value = "task_id") String task_id) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyTaskService.getDifficultyTaskDetail(task_id, user_id);
    }

}

